<?php
namespace BoxAdmin\Controller;

use Think\Controller;

class LogController extends CommonController
{
    public function _initialize()
    {
        parent::_initialize();
        $this->memuNav = "log";
        $this->model = BoxModel("Log");
        $this->id = I('id', 0, 'intval');
    }

    /**
     * [index 日志列表]
     * @return [type] [description]
     */
    public function index()
    {
        $super = C('SUPER_ADMIN');
        $kw = I('get.kw', '', 'trim');

        $where = $this->user_name == $super['username'] ? 'status in (0,1) ' : 'status in (1) and store_id =' . $this->store_id;
        if (!empty($kw)) {
            $where .= ' and (user_name like "%' . $kw . '%" or  ip like "%' . $kw . '%" or content like "%' . $kw . '%")';
        }
        $this->setPager($this->model, 12, $where);
        $this->data = $this->model->where($where)->order('id desc')->limit($this->limit)->select();
        $this->display();
    }

    /**
     * [delete 删除日志]
     * @return [type] [description]
     */
    public function delete()
    {
        $ids = I('get.ids');
        switch (I('get.operation', '', 'intval')) {
            case 1:
                $this->model->where(array('id' => $this->id))->delete();
                break;
            case 2:
                $this->model->where('id in(' . $ids . ')')->delete();
                break;
        }
        $this->redirect('index');
    }
}

?>